# coding=utf-8
__author__ = 'liubin'
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import SingletonThreadPool

# 使用 thread local
# pool_size 和线程池大小保持一致
#engine = create_engine('mysql://root:@localhost:3306/fabrickit?charset=utf8&use_unicode=0',
#                       poolclass=SingletonThreadPool, echo=True, pool_size=16, pool_recycle=10)
engine = create_engine('postgresql://liubin:@localhost:5432/liubin',
                       poolclass=SingletonThreadPool, echo=True, pool_size=16, pool_recycle=10)
Base = declarative_base()
session_factory = sessionmaker(bind=engine)
# 使用 thread local session
Session = scoped_session(session_factory)